home *** CD-ROM | disk | FTP | other *** search
/ Holt Researcher: American History / Holt Researcher: American History.iso / pc / modules / search.dxr / 00001_global movie script.ls next >
Encoding:
Text File  |  2000-01-18  |  9.1 KB  |  314 lines

  1. on startMovie
  2.   set the textHeight of member "selection menu" to 14
  3.   set the textHeight of member "timePeriod translation" to 14
  4. end
  5.  
  6. on findHits
  7.   global gSearchObj, gEnvironObj
  8.   kEmptyType = 0
  9.   kFreeFindType = 3
  10.   t = the ticks
  11.   menuBankObj = getMenuBankObj(gSearchObj)
  12.   hitList = performSearch(1)
  13.   menuType = getMenuSelection(menuBankObj, 2, #criteria)
  14.   if menuType > 0 then
  15.     newList = performSearch(2)
  16.     conjunction = getMenuSelection(menuBankObj, 2, #andOr)
  17.     case conjunction of
  18.       1:
  19.         hitList = intersectSumValues(hitList, newList)
  20.       2:
  21.         hitList = unionSumValues(hitList, newList)
  22.     end case
  23.   end if
  24.   menuType = getMenuSelection(menuBankObj, 3, #criteria)
  25.   if menuType > 0 then
  26.     newList = performSearch(3)
  27.     conjunction = getMenuSelection(menuBankObj, 3, #andOr)
  28.     case conjunction of
  29.       1:
  30.         hitList = intersectSumValues(hitList, newList)
  31.       2:
  32.         hitList = unionSumValues(hitList, newList)
  33.     end case
  34.   end if
  35.   put "Search took " & the ticks - t & " ticks."
  36.   sendToResultsWindow(hitList)
  37. end
  38.  
  39. on performSearch bankNum
  40.   global gSearchObj, gTextBaseObj
  41.   kEmptyType = 0
  42.   kCategoryType = 1
  43.   kTimePeriodType = 2
  44.   kFreeFindType = 3
  45.   menuBankObj = getMenuBankObj(gSearchObj)
  46.   menuType = getMenuSelection(menuBankObj, bankNum, #criteria)
  47.   menuText = getMenuText(menuBankObj, bankNum, #selection)
  48.   case menuType of
  49.     kEmptyType:
  50.       beep()
  51.     kCategoryType:
  52.       selection = getMenuSelection(menuBankObj, bankNum, #selection)
  53.       hitList = getHitList(menuType, selection)
  54.     kTimePeriodType:
  55.       selection = getMenuSelection(menuBankObj, bankNum, #selection)
  56.       hitList = getHitList(menuType, selection)
  57.     kFreeFindType:
  58.       if stripPunct(translate(menuText)) contains " " then
  59.         hitList = getPhraseHits(menuText)
  60.       else
  61.         targetWord = stripPunct(translate(filterChar(menuText, ",")))
  62.         if length(targetWord) < 2 then
  63.           hitList = [:]
  64.           alert("Your free find must contain at least two characters." & RETURN & "Invalid entries will be ignored.")
  65.         else
  66.           hitList = seekPartial(gTextBaseObj, targetWord)
  67.           if not listp(hitList) then
  68.             hitList = [:]
  69.             if hitList <> 1 then
  70.               alert("Error " & hitList & "  when trying to get word hits.")
  71.             end if
  72.           end if
  73.         end if
  74.       end if
  75.   end case
  76.   return hitList
  77. end
  78.  
  79. on sendToResultsWindow scoreList
  80.   criteria = buildCriteriaDisplay()
  81.   if count(scoreList) = 0 then
  82.     hitList = [:]
  83.     titles = EMPTY
  84.   else
  85.     scoreList = relevanceSort(scoreList)
  86.     hitList = getPropListProps(scoreList)
  87.     titles = getTitles(hitList)
  88.   end if
  89.   windowName = "Search Results"
  90.   if windowPresent(windowName) then
  91.     moveToFront(window(windowName))
  92.   else
  93.     tell the stage
  94.       openSearchResultsWindow()
  95.     end tell
  96.   end if
  97.   if windowPresent(windowName) then
  98.     tell window(windowName)
  99.       setSearchResultsList(titles, hitList, criteria)
  100.     end tell
  101.   else
  102.   end if
  103. end
  104.  
  105. on sendKeywordsToResultsWindow scoreList
  106.   criteria = buildCriteriaDisplay()
  107.   if count(scoreList) = 0 then
  108.     hitList = [:]
  109.     titles = EMPTY
  110.   else
  111.     scoreList = AlphaSort(scoreList)
  112.     hitList = getPropListProps(scoreList)
  113.     titles = getTitles(hitList)
  114.   end if
  115.   windowName = "Search Results"
  116.   if windowPresent(windowName) then
  117.     moveToFront(window(windowName))
  118.   else
  119.     tell the stage
  120.       openSearchResultsWindow()
  121.     end tell
  122.   end if
  123.   if windowPresent(windowName) then
  124.     tell window(windowName)
  125.       setSearchResultsList(titles, hitList, criteria)
  126.     end tell
  127.   else
  128.   end if
  129. end
  130.  
  131. on buildCriteriaDisplay
  132.   global gSearchObj
  133.   menuBankObj = getMenuBankObj(gSearchObj)
  134.   if getContext(gSearchObj) = #keywords then
  135.     criteria = "Keyword Search" & RETURN & RETURN
  136.   else
  137.     criteria = getMenuText(menuBankObj, 1, #criteria) & " = "
  138.     put getMenuText(menuBankObj, 1, #selection) & RETURN after menuBankObj
  139.     if getMenuSelection(menuBankObj, 2, #selection) = 0 then
  140.       put RETURN after menuBankObj
  141.     else
  142.       put getMenuText(menuBankObj, 2, #andOr) & " " after menuBankObj
  143.       put getMenuText(menuBankObj, 2, #criteria) & " = " after menuBankObj
  144.       put getMenuText(menuBankObj, 2, #selection) & RETURN after menuBankObj
  145.     end if
  146.     if getMenuSelection(menuBankObj, 3, #selection) = 0 then
  147.       put RETURN after menuBankObj
  148.     else
  149.       put getMenuText(menuBankObj, 3, #andOr) & " " after menuBankObj
  150.       put getMenuText(menuBankObj, 3, #criteria) & " = " after menuBankObj
  151.       put getMenuText(menuBankObj, 3, #selection) & RETURN after menuBankObj
  152.     end if
  153.   end if
  154.   return criteria
  155. end
  156.  
  157. on relevanceSort scoreList
  158.   scoreList = swapPropList(scoreList)
  159.   sort(scoreList)
  160.   resultList = [:]
  161.   n = count(scoreList)
  162.   repeat while n > 0
  163.     subsectionList = [:]
  164.     score = getPropAt(scoreList, n)
  165.     recnum = getAt(scoreList, n)
  166.     addProp(subsectionList, recnum, score)
  167.     repeat while 1
  168.       n = n - 1
  169.       if n = 0 then
  170.         exit repeat
  171.       end if
  172.       if score <> getPropAt(scoreList, n) then
  173.         exit repeat
  174.       end if
  175.       addProp(subsectionList, getAt(scoreList, n), getPropAt(scoreList, n))
  176.     end repeat
  177.     sort(subsectionList)
  178.     end = count(subsectionList)
  179.     repeat with m = 1 to end
  180.       recnum = getPropAt(subsectionList, m)
  181.       resultListValue = getaProp(resultList, recnum)
  182.       if voidp(resultListValue) then
  183.         addProp(resultList, recnum, getAt(subsectionList, m))
  184.         next repeat
  185.       end if
  186.       setaProp(resultList, recnum, resultListValue + getAt(subsectionList, m))
  187.     end repeat
  188.   end repeat
  189.   return resultList
  190. end
  191.  
  192. on AlphaSort scoreList
  193.   newList = [:]
  194.   sort(scoreList)
  195.   end = count(scoreList)
  196.   repeat with m = 1 to end
  197.     CurrProp = getPropAt(scoreList, m)
  198.     NextM = min(m + 1, end)
  199.     NextProp = getPropAt(scoreList, NextM)
  200.     if (CurrProp <> NextProp) or (NextM = end) then
  201.       value = getaProp(scoreList, m)
  202.       setaProp(newList, CurrProp, value)
  203.     end if
  204.   end repeat
  205.   return newList
  206. end
  207.  
  208. on getHitList menuType, selection
  209.   global gTextBaseObj
  210.   menuNameList = ["CATEGORY", "TMPRD"]
  211.   menuName = getAt(menuNameList, menuType)
  212.   hitList = lookup(gTextBaseObj, menuName, integer(selection))
  213.   if not listp(hitList) then
  214.     alert("Error " & hitList & "  when trying to get word hits.")
  215.     hitList = [:]
  216.   end if
  217.   return hitList
  218. end
  219.  
  220. on getPhraseHits targetPhrase
  221.   global gTextBaseObj
  222.   hitList = [:]
  223.   targetPhrase = cleanWOrds(translate(filterChar(targetPhrase, ",")))
  224.   end = the number of words in targetPhrase
  225.   repeat with n = 1 to end
  226.     theWord = word n of targetPhrase
  227.     if length(theWord) > 1 then
  228.       if n = end then
  229.         newHitList = seekPartial(gTextBaseObj, theWord)
  230.       else
  231.         newHitList = seek(gTextBaseObj, theWord)
  232.       end if
  233.       if not listp(newHitList) then
  234.         alert("Error " & newHitList & "  when trying to get phrase hit list.")
  235.         newHitList = [:]
  236.       end if
  237.       if hitList = [:] then
  238.         hitList = value(string(newHitList))
  239.         next repeat
  240.       end if
  241.       hitList = intersectMinValue(hitList, newHitList)
  242.     end if
  243.   end repeat
  244.   if voidp(hitList) then
  245.     hitList = [:]
  246.   end if
  247.   hitList = verifyPhrases(hitList, targetPhrase)
  248.   return hitList
  249. end
  250.  
  251. on cleanWOrds thePhrase
  252.   result = stripPunct(word 1 of thePhrase)
  253.   repeat with n = 2 to the number of words in thePhrase
  254.     result = result && stripPunct(word n of thePhrase)
  255.   end repeat
  256.   return result
  257. end
  258.  
  259. on verifyPhrases hitList, targetPhrase
  260.   phraseObj = new(script("phrase class"))
  261.   end = count(hitList)
  262.   resultList = [:]
  263.   score = 100
  264.   repeat with recnum = 1 to end
  265.     hasPhrase = fileContainsPhrase(phraseObj, getPropAt(hitList, recnum), targetPhrase)
  266.     updateStage()
  267.     if hasPhrase then
  268.       score = getAt(hitList, recnum)
  269.       addProp(resultList, getPropAt(hitList, recnum), score)
  270.     end if
  271.   end repeat
  272.   phraseObj = 0
  273.   return resultList
  274. end
  275.  
  276. on getTitles recordNumberList
  277.   titlesText = the text of field "titles list" of castLib "Update.cst"
  278.   titles = EMPTY
  279.   repeat with recnum in recordNumberList
  280.     put line recnum of titlesText & RETURN after titlesText
  281.   end repeat
  282.   return titles
  283. end
  284.  
  285. on alphabetClick whichField
  286.   global gSearchObj
  287.   shadeLoc = [5, 20, 35, 50, 64, 78, 92, 107, 119, 131, 145, 159, 173, 189, 204, 219, 233, 249, 263, 277, 291, 305, 321, 337, 351, 364, 380]
  288.   end = count(shadeLoc)
  289.   repeat with i = 2 to end
  290.     if (the clickLoc).locH < getAt(shadeLoc, i) then
  291.       kGrayBoxSprite = 6
  292.       puppetSprite(kGrayBoxSprite, 1)
  293.       boxLoc = getAt(shadeLoc, i - 1)
  294.       set the locH of sprite kGrayBoxSprite to boxLoc
  295.       letter = char i - 1 of "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  296.       if letter = "A" then
  297.         setThumb(getScrollbarObj(gSearchObj), 0)
  298.       else
  299.         whichField.scrollTop = 0
  300.         CharNum = offset("‚Äî " & letter, the text of field whichField)
  301.         if CharNum > 0 then
  302.           charLoc = charPosToLoc(whichField, CharNum)
  303.           lineNumber = locVToLinePos(whichField, charLoc.locV)
  304.           if the machineType = 256 then
  305.             lineNumber = lineNumber - 1
  306.           end if
  307.           setThumb(getScrollbarObj(gSearchObj), lineNumber)
  308.         end if
  309.       end if
  310.       exit repeat
  311.     end if
  312.   end repeat
  313. end
  314.